package com.smashcrush.client.gwt;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.RootPanel;
import com.smashcrush.client.gwt.manager.ScriptsManager;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Application implements EntryPoint {

	private final MyWidgetGinjector injector = GWT
			.create(MyWidgetGinjector.class);

	public void onModuleLoad() {

		Grid grid = new Grid(1, 1);
		grid.setSize("100%", "100%");
		grid.getCellFormatter().setAlignment(0, 0,
				HasHorizontalAlignment.ALIGN_CENTER,
				HasVerticalAlignment.ALIGN_MIDDLE);
		RootPanel.get().add(grid);

		final Login login = new Login();
		grid.setWidget(0, 0, login);

		login.setOnLoginCommand(new Command() {

			@Override
			public void execute() {
				ScriptsManager.get().loadData(new Command() {

					@Override
					public void execute() {
						RootPanel.get().remove(0);
						RootPanel.get().add(injector.getWorkspace());
					}
				});

			}
		});

	}

}
